
using namespace std;
const int maxn = 2e5+10;
int a[2*maxn];
int b[maxn];
int rem[maxn][2];
int ans[maxn];
int main()
{
	

		int n;
		scanf(" %d",&n);
		for(int i = 0;i<n;i++)
		{
			scanf(" %d",&a[i]);
			a[i+n] = a[i];
			rem[a[i]][0] = i;
			rem[a[i]][1] = i+n;
		
		}
		int cnt = 0;
		for(int i = 0;i<n;i++)
		{
			scanf(" %d",&b[i]);
			rem[b[i]][0] -= i;
			rem[b[i]][1] -= i;
			if(rem[b[i]][0]>=0&&rem[b[i]][0]<=n)
			{
				ans[cnt++] = rem[b[i]][0];
			}
			if(rem[b[i]][1]>=0&&rem[b[i]][1]<=n)
			{
				ans[cnt++] = rem[b[i]][1];
			}
		}
		sort(ans,ans+cnt);
		int m = 1;
		for(int i = cnt-1;i>0;i--)
		{
			if(ans[i]==ans[i-1]) m++;
			else break;
		}
		printf("%d\n",m);
	
}
